package com.leyou.item.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ShenMin
 * @date 2021/7/14 17:30
 * @description
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    @GetMapping("/{id}")
    public ResponseEntity<List<CategoryDTO>> listCategoryById(@PathVariable(value = "id") Long id) {
        return ResponseEntity.ok(categoryService.listCategoryById(id));
        //return categoryService.listCategoryBySortId(id);
    }

    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> listCategoryByIds(@RequestParam("ids") List<Long> ids) {
        return ResponseEntity.ok(categoryService.listCategoryByIds(ids));
    }


    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> listCategoryByBid(@RequestParam("id") Long bid) {
        return ResponseEntity.ok(categoryService.listCategoryByBid(bid));
    }

    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> listCategoryByPid(@RequestParam(value = "pid", required = false, defaultValue = "0") Long pid) {
        return ResponseEntity.ok(categoryService.listCategoryByPid(pid));
    }
}
